import {
	defineStore
} from "pinia";

export const productStore = defineStore('product', {
	state: () => ({
		info: [],
		update: false,
		version: 0,
		fingerprint: 0
	}),
	getters: {
		getInfo(state) {
			return state.info
		},
		getUpdate(state) {
			return state.update
		},
		getVersion(state) {
			return state.version
		},
		getFingerprint(state) {
			return state.fingerprint
		}
	},
	actions: {
		setInfo(data) {
			this.info = data;
		},
		setUpdate(data) {
			this.update = data
		},
		setVersion(data) {
			this.version = data
		},
		setFingerprint(number) {
			console.log("添加指纹数量", number)
			this.fingerprint = number
		}
	}
})

export const bluetoothStore = defineStore('bluetooth', {
	state: () => ({
		name: [],
		deviceId: []
	}),
	getters: {
		getName(state) {
			return state.name
		},
		getDeviceId(state) {
			return state.deviceId
		}
	},
	actions: {
		setName(data) {
			this.name = data;
		},
		setDeviceId(date) {
			this.deviceId = name;
		}
	}
})

export const userStore = defineStore('userStore', {
	state: () => ({
		info: {},
		number: 0,
		device: [],
		product: [],
	}),
	getters: {
		getInfo(state) {
			return state.info;
		},
		isLogin(state) {
			return state.info?.token ? true : false;
		},
		getNumber(state) {
			return state.number;
		},
		getOnline(state) {
			return state.device.length;
		},
		getDevice(state) {
			return state.device;
		},
		getToken(state) {
			return state.info?.token;
		},
		getProduct(state) {
			return state.product
		}
	},
	actions: {
		setInfo(data) {
			this.info = data;
		},
		setNumber(number) {
			this.number = number;
		},
		setDevice(data) {
			this.device = data;
		},
		logout() {
			this.info = {}
		},
		setProduct(data) {
			this.product = data;
		}
	},
	persist: true
});